package org.filecollector.basics.configs;

import com.google.gson.GsonBuilder;
import lombok.Getter;
import lombok.Setter;

import java.nio.file.Path;
import java.util.ArrayList;

public class ConfigsSingleton {

    @Getter
    private static final GsonBuilder configGsonBuilder = new GsonBuilder();

    @Getter
    private static final ConfigsDao defaultConfigDAO = new ConfigsDao(
            new String[]{"./standardFileCollector"},
            0L ,
            Long.MAX_VALUE,
            new String[]{"debug", "checksum_algorithm=SHA-256", "OS=linux", "FS=ext4"}
    );

    @Getter
    @Setter
    private static Configs config = Configs.getDefault();

    public static ArrayList<Path> getFilesDir() {
        return config.getTrackingDirectories();
    }

    public static boolean containsAnyFlag(String... flags) {
        for (var flag : flags) {
            if (config.containsFlag(flag)) {
                return true;
            }
        }
        return false;
    }

    public static boolean containsAllFlags(String... flags) {
        for (var flag : flags) {
            if (!config.containsFlag(flag)) {
                return false;
            }
        }
        return true;
    }

    public static boolean containsFlag(String flag) {
        return config.containsFlag(flag);
    }

    public static String getStatus(String statusKey) {
        return config.getStatus(statusKey);
    }


    public static <T extends RuntimeException> String getStatusOrThrow(String statusKey, T ex) {
        var ret = getStatus(statusKey);
        if (ret.equals("NULL")) {
            throw ex;
        }
        return ret;
    }
}
